package logic

import (
	"context"

	"jinrigaoping/rpc/sys/internal/svc"
	"jinrigaoping/rpc/sys/sys"

	"github.com/zeromicro/go-zero/core/logx"
)

type SysMenuInfoLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewSysMenuInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SysMenuInfoLogic {
	return &SysMenuInfoLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *SysMenuInfoLogic) SysMenuInfo(in *sys.SysMenuInfoReq) (*sys.SysMenuInfoRes, error) {

	info, err := l.svcCtx.SysMenuModel.FindOne(l.ctx, in.MenuId)
	if err != nil {
		return nil, err
	}

	return &sys.SysMenuInfoRes{
		MenuId:      info.MenuId,
		ParentId:    info.ParentId,
		Name:        info.Name,
		Component:   info.Component,
		IsLink:      info.IsLink == 1,
		MenuSort:    info.MenuSort,
		Path:        info.Path,
		Redirect:    info.Redirect,
		Title:       info.Title,
		Icon:        info.Icon,
		IsHide:      info.IsHide == 1,
		IsKeepAlive: info.IsKeepAlive == 1,
		IsAffix:     info.IsAffix == 1,
		LinkUrl:     info.LinkUrl,
		MenuType:    info.MenuType,
		IsIframe:    info.IsIframe == 1,
	}, nil
}
